package com.discovery.main;

import java.util.Random;

public class Util
{
   public static String getRandomAlphaNumericString(final int len)
   {
      final String ALPHA_NUM = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      final StringBuffer sb = new StringBuffer(len);
      for (int i = 0; i < len; i++) {
         final int ndx = (int) (Math.random() * ALPHA_NUM.length());
         sb.append(ALPHA_NUM.charAt(ndx));
      }
      return sb.toString();
   }

   public static int getRandomInteger(final int aStart,
                                      final int aEnd,
                                      final Random aRandom)
   {
      if (aStart > aEnd) {
         throw new IllegalArgumentException("Start cannot exceed End.");
      }
      final long range = (long) aEnd - (long) aStart + 1;
      final long fraction = (long) (range * aRandom.nextDouble());
      final int randomNumber = (int) (fraction + aStart);
      return randomNumber;
   }
}
